def poor(a):
    b = True
    for c in range(2, int(a ** 0.5)+1):
        if a % c == 0:
            b = False
            break
    return b

d = int(input())
if d < 1000 or d > 9999:
    print(0)
else:
    sntz = str(d)
    ro = 0
    for s in range(len(sntz)):
        for k in range(s+1, len(sntz)+1):
            meow = int(sntz[s:k])
            if poor(meow):
                ro = max(ro, meow)
    print(ro)
